﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using ORMAC.CodeGen;
using Test;
using ORMAC;
using ORMAC.UnitTest.Helper;
using System.Diagnostics;
namespace ORMAC.UnitTest
{
    [TestFixture]
    public class NorthwindTester
    {
        string TestDataCnn=Settings.Default.NorthwindConnectionString;
        static IReader orm;
        public NorthwindTester()
        {
        }
        [Test]
        public void Init()
        {
            orm = new OReader();
            orm.SetConnectionString(TestDataCnn);
            orm
                .LoadObject<OOrders>(o => null);
            var res = orm.LoadFromDatabase<OOrders>();

        }
        [Test]
        public void TestObjectCount()
        {
            ORMAC.Core.PerformanceCounters.ContextTime = 0;

            Stopwatch s = new Stopwatch();
            s.Start();
            var 
                res = orm.LoadFromDatabase<OOrders>();
            s.Stop();
            Console.WriteLine("ORMAC Time:"+ s.ElapsedMilliseconds);

            Console.WriteLine("Context Time:" + ORMAC.Core.PerformanceCounters.ContextTime.ToString());
            int adoCount = new ADOHelper(TestDataCnn).GetTableRowCount<OOrders>();
            Assert.AreEqual(adoCount, res.Count);
        }
        [Test]
        public void TestObjectGetAll()
        {
            IReader orm = new OReader();
            orm.SetConnectionString(TestDataCnn);
            orm
                .LoadObject<OOrders>(o => null);
            Stopwatch s = new Stopwatch();
            s.Start();
            var res = orm.LoadFromDatabase<OOrders>();
            s.Stop();
            Console.WriteLine("ORMAC Time:" + s.ElapsedMilliseconds);
            int adoCount = new ADOHelper(TestDataCnn).GetTableRows<OOrders>();
            Assert.AreEqual(adoCount, res.Count);
        }
    }
}
